/*
Copyright (c) 2009-2010, Warwick Warp Limited
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the Warwick Warp Limited nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL WARWICK WARP LIMITED BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "warray_vmath.h"

#ifdef USE_ACCELERATE
#include <Accelerate/Accelerate.h>

namespace {

// We need these routines to map onto the split-complex types used by 
// Accelerate's DSP functions
// Because of the way the types are defined we must also, unfortunately, cast 
// away any const-ness the type has.
DSPSplitComplex split(const std::complex<float> *x)
{
	DSPSplitComplex result;
	result.realp = const_cast<float*>(reinterpret_cast<const float*>(x));
	result.imagp = result.realp+1;
	return result;
}

DSPDoubleSplitComplex split(const std::complex<double> *x)
{
	DSPDoubleSplitComplex result;
	result.realp = const_cast<double*>(reinterpret_cast<const double*>(x));
	result.imagp = result.realp+1;
	return result;
}

} // namespace


template<> void warp::vm::add<float>(size_t n, const float *a, const float *b, float *c)
{
	vDSP_vadd(a,1,b,1,c,1,n);
}

template<> void warp::vm::sub<float>(size_t n, const float *a, const float *b, float *c)
{
	vDSP_vsub(b,1,a,1,c,1,n);
}

template<> void warp::vm::mul<float>(size_t n, const float *a, const float *b, float *c)
{
	vDSP_vmul(a,1,b,1,c,1,n);
}

template<> void warp::vm::div<float>(size_t n, const float *a, const float *b, float *c)
{
	// NB: Not sure why the inputs to vdiv aren't const
	vDSP_vdiv(const_cast<float*>(b),1,const_cast<float*>(a),1,c,1,n);
}

template<> void warp::vm::add<double>(size_t n, const double *a, const double *b, double *c)
{
	vDSP_vaddD(a,1,b,1,c,1,n);
}

template<> void warp::vm::sub<double>(size_t n, const double *a, const double *b, double *c)
{
	vDSP_vsubD(b,1,a,1,c,1,n);
}

template<> void warp::vm::mul<double>(size_t n, const double *a, const double *b, double *c)
{
	vDSP_vmulD(a,1,b,1,c,1,n);
}

template<> void warp::vm::div<double>(size_t n, const double *a, const double *b, double *c)
{
	vDSP_vdivD(const_cast<double*>(b),1,const_cast<double*>(a),1,c,1,n);
}

template<> void warp::vm::add< std::complex<float> >(size_t n, const  std::complex<float>  *a, const  std::complex<float>  *b,  std::complex<float>  *c)
{
	DSPSplitComplex as = split(a);
	DSPSplitComplex bs = split(b);
	DSPSplitComplex cs = split(c);
	vDSP_zvadd(&as,2,&bs,2,&cs,2,n);
}

template<> void warp::vm::sub< std::complex<float> >(size_t n, const  std::complex<float>  *a, const  std::complex<float>  *b,  std::complex<float>  *c)
{
	DSPSplitComplex as = split(a);
	DSPSplitComplex bs = split(b);
	DSPSplitComplex cs = split(c);
	// Err... the arguments for complex subtraction appear to be the other way around!
	vDSP_zvsub(&as,2,&bs,2,&cs,2,n);
}

template<> void warp::vm::mul< std::complex<float> >(size_t n, const  std::complex<float>  *a, const  std::complex<float>  *b,  std::complex<float>  *c)
{
	// The vDSP routines do not appear to support aliasing for zvmul
	if(a==c || b==c)
	{
		std::transform(a,a+n,b,c,std::multiplies< std::complex<float> >());
		return;
	}
	
	DSPSplitComplex as = split(a);
	DSPSplitComplex bs = split(b);
	DSPSplitComplex cs = split(c);
	vDSP_zvmul(&as,2,&bs,2,&cs,2,n,1);
}

template<> void warp::vm::mulconj<float>(size_t n, const  std::complex<float>  *a, const  std::complex<float>  *b,  std::complex<float>  *c)
{
	// The vDSP routines do not appear to support aliasing for zvmul
	if(a==c || b==c)
	{
		std::transform(a,a+n,b,c,warp::detail::multiplies_conj<float>());
		return;
	}
	
	DSPSplitComplex as = split(a);
	DSPSplitComplex bs = split(b);
	DSPSplitComplex cs = split(c);
	vDSP_zvmul(&bs,2,&as,2,&cs,2,n,-1);
}

template<> void warp::vm::div< std::complex<float> >(size_t n, const  std::complex<float>  *a, const  std::complex<float>  *b,  std::complex<float>  *c)
{
	DSPSplitComplex as = split(a);
	DSPSplitComplex bs = split(b);
	DSPSplitComplex cs = split(c);
	vDSP_zvdiv(&bs,2,&as,2,&cs,2,n);
}

template<> void warp::vm::add< std::complex<double> >(size_t n, const  std::complex<double>  *a, const  std::complex<double>  *b,  std::complex<double>  *c)
{
	DSPDoubleSplitComplex as = split(a);
	DSPDoubleSplitComplex bs = split(b);
	DSPDoubleSplitComplex cs = split(c);
	vDSP_zvaddD(&as,2,&bs,2,&cs,2,n);
}

template<> void warp::vm::sub< std::complex<double> >(size_t n, const  std::complex<double>  *a, const  std::complex<double>  *b,  std::complex<double>  *c)
{
	DSPDoubleSplitComplex as = split(a);
	DSPDoubleSplitComplex bs = split(b);
	DSPDoubleSplitComplex cs = split(c);
	// The complex version of sub has the arguments in the other order...
	vDSP_zvsubD(&as,2,&bs,2,&cs,2,n);
}

template<> void warp::vm::mul< std::complex<double> >(size_t n, const  std::complex<double>  *a, const  std::complex<double>  *b,  std::complex<double>  *c)
{
	DSPDoubleSplitComplex as = split(a);
	DSPDoubleSplitComplex bs = split(b);
	DSPDoubleSplitComplex cs = split(c);
	vDSP_zvmulD(&as,2,&bs,2,&cs,2,n,1);
}

template<> void warp::vm::mulconj<double>(size_t n, const  std::complex<double>  *a, const  std::complex<double>  *b,  std::complex<double>  *c)
{
	DSPDoubleSplitComplex as = split(a);
	DSPDoubleSplitComplex bs = split(b);
	DSPDoubleSplitComplex cs = split(c);
	vDSP_zvmulD(&bs,2,&as,2,&cs,2,n,-1);
}

template<> void warp::vm::div< std::complex<double> >(size_t n, const  std::complex<double>  *a, const  std::complex<double>  *b,  std::complex<double>  *c)
{
	DSPDoubleSplitComplex as = split(a);
	DSPDoubleSplitComplex bs = split(b);
	DSPDoubleSplitComplex cs = split(c);
	vDSP_zvdivD(&bs,2,&as,2,&cs,2,n);
}

template<> void warp::vm::square<float>(size_t n, const float *a, float *b)
{
	vDSP_vsq(a,1,b,1,n);
}

template<> void warp::vm::square<double>(size_t n, const double *a, double *b)
{
	vDSP_vsqD(a,1,b,1,n);
}

template<> void warp::vm::conj<float>(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	DSPSplitComplex as = split(a);
	DSPSplitComplex bs = split(b);
	vDSP_zvconj(&as,2,&bs,2,n);
}

template<> void warp::vm::conj<double>(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	DSPDoubleSplitComplex as = split(a);
	DSPDoubleSplitComplex bs = split(b);
	vDSP_zvconjD(&as,2,&bs,2,n);
}

template<> void warp::vm::abs<float>(size_t n, const float *a, float *b)
{
	vDSP_vabs(const_cast<float*>(a),1,b,1,n);
}

template<> void warp::vm::abs<double>(size_t n, const double *a, double *b)
{
	vDSP_vabsD(const_cast<double*>(a),1,b,1,n);
}

template<> void warp::vm::abs<float>(size_t n, const std::complex<float> *a, float *b)
{
	DSPSplitComplex as = split(a);
	vDSP_zvabs(&as,2,b,1,n);
}

template<> void warp::vm::abs<double>(size_t n, const std::complex<double> *a, double *b)
{
	DSPDoubleSplitComplex as = split(a);
	vDSP_zvabsD(&as,2,b,1,n);
}

template<> void warp::vm::inv<float>(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvrecf(b,a,&in);
}

template<> void warp::vm::inv<double>(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvrec(b,a,&in);
}

template<> void warp::vm::sqrt<float>(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvsqrtf(b,a,&in);
}

template<> void warp::vm::sqrt<double>(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvsqrt(b,a,&in);
}

template<> void warp::vm::sqrt< std::complex<float> >(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_sqrt< std::complex<float> >());
}

template<> void warp::vm::sqrt< std::complex<double> >(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_sqrt< std::complex<double> >());
}

template<> void warp::vm::invsqrt<float>(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvrsqrtf(b,a,&in);
}

template<> void warp::vm::invsqrt<double>(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvrsqrt(b,a,&in);
}

template<> void warp::vm::pow<float>(size_t n, const float *a, const float *b, float *c)
{
	int in=int(n);
	vvpowf(c,b,a,&in);
}

template<> void warp::vm::pow<double>(size_t n, const double *a, const double *b, double *c)
{
	int in=int(n);
	vvpow(c,b,a,&in);
}

template<> void warp::vm::pow< std::complex<float> >(size_t n, const std::complex<float> *a, const std::complex<float> *b, std::complex<float> *c)
{
	std::transform(a,a+n,b,c,warp::detail::choose_pow< std::complex<float> >());
}

template<> void warp::vm::pow< std::complex<double> >(size_t n, const std::complex<double> *a, const std::complex<double> *b, std::complex<double> *c)
{
	std::transform(a,a+n,b,c,warp::detail::choose_pow< std::complex<double> >());
}

template<> void warp::vm::pow<float>(size_t n, const float *a, const float& b, float *c)
{
	std::transform(a,a+n,c,std::bind2nd(warp::detail::choose_pow<float>(),b));
}

template<> void warp::vm::pow<double>(size_t n, const double *a, const double& b, double *c)
{
	std::transform(a,a+n,c,std::bind2nd(warp::detail::choose_pow<double>(),b));
}

template<> void warp::vm::pow< std::complex<float> >(size_t n, const std::complex<float> *a, const std::complex<float>& b, std::complex<float> *c)
{
	std::transform(a,a+n,c,std::bind2nd(warp::detail::choose_pow< std::complex<float> >(),b));
}

template<> void warp::vm::pow< std::complex<double> >(size_t n, const std::complex<double> *a, const std::complex<double>& b, std::complex<double> *c)
{
	std::transform(a,a+n,c,std::bind2nd(warp::detail::choose_pow< std::complex<double> >(),b));
}

template<> void warp::vm::hypot<float>(size_t n, const float *a, const float *b, float *c)
{
	vDSP_vdist(
		const_cast<float*>(a),1,
		const_cast<float*>(b),1,
		c,1,
		n);
}

template<> void warp::vm::hypot<double>(size_t n, const double *a, const double *b, double *c)
{
	vDSP_vdistD(
		const_cast<double*>(a),1,
		const_cast<double*>(b),1,
		c,1,
		n);
}

template<> void warp::vm::exp<float>(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvexpf(b,a,&in);
}

template<> void warp::vm::exp<double>(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvexp(b,a,&in);
}

template<> void warp::vm::exp< std::complex<float> >(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_exp< std::complex<float> >());
}

template<> void warp::vm::exp< std::complex<double> >(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_exp< std::complex<double> >());
}

template<> void warp::vm::ln<float>(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvlogf(b,a,&in);
}

template<> void warp::vm::ln<double>(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvlog(b,a,&in);
}

template<> void warp::vm::ln< std::complex<float> >(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_log< std::complex<float> >());
}

template<> void warp::vm::ln< std::complex<double> >(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_log< std::complex<double> >());
}

template<> void warp::vm::log10<float>(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvlog10f(b,a,&in);
}

template<> void warp::vm::log10<double>(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvlog10(b,a,&in);
}

template<> void warp::vm::log10< std::complex<float> >(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_log10< std::complex<float> >());
}

template<> void warp::vm::log10< std::complex<double> >(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_log10< std::complex<double> >());
}

template<> void warp::vm::sin(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvsinf(b,a,&in);
}

template<> void warp::vm::sin(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvsin(b,a,&in);
}

template<> void warp::vm::sin(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_sin< std::complex<float> >());
}

template<> void warp::vm::sin(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_sin< std::complex<double> >());
}

template<> void warp::vm::cos(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvcosf(b,a,&in);
}

template<> void warp::vm::cos(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvcos(b,a,&in);
}

template<> void warp::vm::cos(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_cos< std::complex<float> >());
}

template<> void warp::vm::cos(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_cos< std::complex<double> >());
}

template<> void warp::vm::sincos(size_t n, const float *a, float *b, float *c)
{
	int in=int(n);
	vvsincosf(b,c,a,&in);
}

template<> void warp::vm::sincos(size_t n, const double *a, double *b, double *c)
{
	int in=int(n);
	if(a==b)
	{
		// vvsincos doesn't cope with aliasing of a and b
		// but does cope with aliasing of a and c, so swap the 
		// results during computation
		vvsincos(c,b,a,&in);
		vDSP_vswapD(b,1,c,1,n);
	}
	else
		vvsincos(b,c,a,&in);
}

template<> void warp::vm::cis(size_t n, const float *a, std::complex<float> *b)
{
	int in=int(n);
	vvcosisinf(b,a,&in);
}

template<> void warp::vm::cis(size_t n, const double *a, std::complex<double> *b)
{
	int in=int(n);
	vvcosisin(b,a,&in);
}

template<> void warp::vm::tan(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvtanf(b,a,&in);
}

template<> void warp::vm::tan(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvtan(b,a,&in);
}

template<> void warp::vm::tan(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_tan< std::complex<float> >());
}

template<> void warp::vm::tan(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_tan< std::complex<double> >());
}

template<> void warp::vm::acos(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvacosf(b,a,&in);
}

template<> void warp::vm::acos(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvacos(b,a,&in);
}

template<> void warp::vm::acos(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_acos< std::complex<float> >());
}

template<> void warp::vm::acos(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_acos< std::complex<double> >());
}

template<> void warp::vm::asin(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvasinf(b,a,&in);
}

template<> void warp::vm::asin(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvasin(b,a,&in);
}

template<> void warp::vm::asin(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_asin< std::complex<float> >());
}

template<> void warp::vm::asin(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_asin< std::complex<double> >());
}

template<> void warp::vm::atan(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvatanf(b,a,&in);
}

template<> void warp::vm::atan(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvatan(b,a,&in);
}

template<> void warp::vm::atan(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_atan< std::complex<float> >());
}

template<> void warp::vm::atan(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_atan< std::complex<double> >());
}

template<> void warp::vm::atan2(size_t n, const float *a, const float *b, float *c)
{
	int in=int(n);
	vvatan2f(c,a,b,&in);
}

template<> void warp::vm::atan2(size_t n, const double *a, const double *b, double *c)
{
	int in=int(n);
	vvatan2(c,a,b,&in);
}

template<> void warp::vm::sinh<float>(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvsinhf(b,a,&in);
}

template<> void warp::vm::sinh<double>(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvsinh(b,a,&in);
}

template<> void warp::vm::sinh< std::complex<float> >(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_sinh< std::complex<float> >());
}

template<> void warp::vm::sinh< std::complex<double> >(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_sinh< std::complex<double> >());
}

template<> void warp::vm::cosh<float>(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvcoshf(b,a,&in);
}

template<> void warp::vm::cosh<double>(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvcosh(b,a,&in);
}

template<> void warp::vm::cosh< std::complex<float> >(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_cosh< std::complex<float> >());
}

template<> void warp::vm::cosh< std::complex<double> >(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_cosh< std::complex<double> >());
}

template<> void warp::vm::tanh<float>(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvtanhf(b,a,&in);
}

template<> void warp::vm::tanh<double>(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvtanh(b,a,&in);
}

template<> void warp::vm::tanh< std::complex<float> >(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_tanh< std::complex<float> >());
}

template<> void warp::vm::tanh< std::complex<double> >(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_tanh< std::complex<double> >());
}

template<> void warp::vm::asinh<float>(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvasinhf(b,a,&in);
}

template<> void warp::vm::asinh<double>(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvasinh(b,a,&in);
}

template<> void warp::vm::asinh< std::complex<float> >(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_asinh< std::complex<float> >());
}

template<> void warp::vm::asinh< std::complex<double> >(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_asinh< std::complex<double> >());
}

template<> void warp::vm::acosh<float>(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvacoshf(b,a,&in);
}

template<> void warp::vm::acosh<double>(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvacosh(b,a,&in);
}

template<> void warp::vm::acosh< std::complex<float> >(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_acosh< std::complex<float> >());
}

template<> void warp::vm::acosh< std::complex<double> >(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_acosh< std::complex<double> >());
}

template<> void warp::vm::atanh<float>(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvatanhf(b,a,&in);
}

template<> void warp::vm::atanh<double>(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvatanh(b,a,&in);
}

template<> void warp::vm::atanh< std::complex<float> >(size_t n, const std::complex<float> *a, std::complex<float> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_atanh< std::complex<float> >());
}

template<> void warp::vm::atanh< std::complex<double> >(size_t n, const std::complex<double> *a, std::complex<double> *b)
{
	std::transform(a,a+n,b,warp::detail::choose_atanh< std::complex<double> >());
}

template<> void warp::vm::floor<float>(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvfloorf(b,a,&in);
}

template<> void warp::vm::floor<double>(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvfloor(b,a,&in);
}

template<> void warp::vm::ceil<float>(size_t n, const float *a, float *b)
{
	int in=int(n);
	vvceilf(b,a,&in);
}

template<> void warp::vm::ceil<double>(size_t n, const double *a, double *b)
{
	int in=int(n);
	vvceil(b,a,&in);
}

#endif
